<?php

namespace App\Http\Controllers;
use Mail;
use Illuminate\Http\Request;
use DB;
use Hash;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class EmailController extends Controller
{
	public function getSendmail(Request $request){
	$str = rand(10000,99999);
	session(['yzm'=>$str]);
	$email = $request->all()['email'];
    echo $str;
	// dd($email);
    Mail::raw('尊敬的用户你的验证码是'.$str, function ($message)use($email) {
         //设置邮件标题
        $message->subject('哈哈马激活邮件'); 
         //发送给谁 
        $message->to($email); 
        });
     }

    public function postZhuce(Request $request)
    {
    	// var_dump(session('yzm'));
    	$data = $request->only('username','password','email');
    	$data['password'] = Hash::make($request->input('password'));
        $data['state'] = 0;
    	// var_dump($data);
    	if(session('yzm') == $request->input('num')){
    		$res = DB::table('users')->insert($data);
    		return redirect('/');
    	}
    }

}
